function refresh(){
    $("#dataTable").bootstrapTable("removeAll");
    $("#dataTable").bootstrapTable('refresh');
}
function editData(rowId){
    layer.open({
        move: false,
        type: 2,
        title: '新建',
        area: ['850px', '360px'],
        content: 'clean_update.html?rowId='+rowId,
        btn: ['保存','取消'],
        btnAlign: 'c',
        yes: function (index, layero) {
            var openWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
            var ret= openWin.yesOperator();
            if(ret){
                layer.close(index);
                refresh();
            }
        }, cancel: function (index) {
            layer.close(index);
        }
    });
}
//新建弹框
function addServer(){
	layer.open({
        move: false,
        type: 2,
        title: '新建服务',
        area: ['850px', '360px'],
        content: 'clean_add.html',
        btn: ['保存','取消'],
        btnAlign: 'c',
        yes: function (index, layero) {
            var openWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
            var ret= openWin.yesOperator();
            if(ret){
                layer.close(index);
                refresh();
            }
        }, cancel: function (index) {
            layer.close(index);
        }
    });
}
//搜索以前将页码换成第一页
function searchInit(){
    var options=$("#dataTable").bootstrapTable("getOptions");
    options.pageNumber=1;
    $("#dataTable").bootstrapTable('refreshOptions',options);
}
$(function () {

    //重置表单
    $("#searchReset").on("click",function(){

        $("#searchForm input[type='text']").val("");
        $('#dataTable').bootstrapTable('refresh');
    });
    //渲染表格
    var columns = cleanList.columnsInit();
    var table = cleanList.gridInit(columns);
    //var datas = cleanList.dataInit();
    //$("#dataTable").bootstrapTable("append",datas);
    //点击删除按钮信息弹出框
    $("#del-btn").click(function(){
        var len = $("#dataTable input:checked").length;
        if (len == 0) {
            //未选中数据提示框
            layer.msg('请选择数据',  {time:1000});
        } else {
            layer.confirm('确定要删除这条数据吗？',
                {icon: 3, title: '提示', area: '300px', btnAlign: 'c'}, function (index) {
                    var rows= $("#dataTable").bootstrapTable('getSelections');
                    var rowIds = [];
                    for (var i = 0; i < rows.length; i++) {
                        rowIds.push(rows[i].id);
                    }
                    $$.ajax({
                        url: "/rest/IotCleanBusiness/remove",
                        data: {
                            id : rowIds.join(',')
                        },
                        success: function() {
                            refresh();
                        }
                    });
                    layer.close(index);
                });
        }

    });

    $("#serachBtn").click(function(){
        searchInit();
        refresh();
    });
    $('#serachBtn').bind('keypress',function(e){
        searchInit();

        if(e.keyCode == 13){
            refresh();
        }
    });

    $('#cleanCode').bind('keypress',function(e){


        if(e.keyCode == 13){
            searchInit();
            refresh();
        }
    });
    $('#cleanName').bind('keypress',function(e){


        if(e.keyCode == 13){
            searchInit();
            refresh();
        }
    });
});
(function(undefined) {
    "use strict"
    var _global;
    function result(args,fn){
        var argsArr = Array.prototype.slice.call(args);
        if(argsArr.length > 0){
            return argsArr.reduce(fn);
        } else {
            return 0;
        }
    }
    var cleanList = {
        columnsInit:function(){
            return  [
                {
                    field: 'id',
                    title: '序号',
                    formatter: function (value, row, index) {
                            return     index+1 ;
                    }
                },
                {field:"cleanCode",title:"清理编码" },
                {field:"cleanName",title:"清理名称" },
                {field:"rowSort",title:"排序号" },
                {field:"remarks",title:"备注" },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        if(value == '1'){
                            return [
                                '<span class="sys-type-bg pro-status-green">启用</span>'
                            ].join('');
                        }
                        return [
                            '<span class="sys-type-bg pro-status-red">停用</span>'
                        ].join('');

                    }

                },{
                    checkbox: true
                },{
                    field: 'edit',
                    title: '编辑',
                    width: 100,
                    align: 'center',
                    formatter: function (value, row, index) {
                        return [
                            '<li><a href="javascript:void(0)" onclick="editData(\''+row.id+'\');" title="编辑" class="opt-icon"><i class="glyphicon glyphicon-pencil"></i></a></li>',
                        ].join('');
                    }

                }]
        },
        gridInit:function(columns) {
            return $("#dataTable").bootstrapTable({
                method: "post",
                contentType: "application/x-www-form-urlencoded",
                url: $$.restServerUrl + '/bootstrap/basegrid/IotCleanBusiness/list',
                columns: columns,
                undefinedText: '-',
                striped: 'true',
                classes: 'table table-hover qxttable',
                pagination: 'true',
                clickToSelect: true,
                singleSelect: false,
                sidePagination: "server",
                queryParamsType: "page",
                sortSide: 'client',
                sortable: true,
                pageNumber: 1,
                pageSize: 5,
                idField: 'id',
                silentSort: true,
                pageList: [
                	10, 20, 50, 100
                ],
                onClickRow: function (row, $element, field) {
                    $("#dataTable").bootstrapTable("uncheckAll");
                },
                queryParams: function queryParams(params) {   //设置查询参数

                    var args = {};
                    args.c_cleanCode_7=$("#cleanCode").val();
                    args.c_cleanName_7=$("#cleanName").val();
                    args.page = params.pageNumber - 1; //    params.pageNumber
                    args.pageSize = params.pageSize;     //params.pageSize
                    args.isPage = 1;
                    //args.order=orderStr;
                    var paramStr = JSON.stringify(args);

                    //alert(params.pageNumber+":"+params.pageSize);
                    //alert(orderStr);
                    var param = {
                        params: paramStr
                    };
                    return param;
                }
            });
        },
        dataInit:function(){
            return  [
            ]
        }
    }

    // 将插件对象暴露给全局对象
    _global = (function(){ return this || (0, eval)('this'); }());
    if (typeof module !== "undefined" && module.exports) {
        module.exports = cleanList;
    } else if (typeof define === "function" && define.amd) {
        define(function(){return cleanList;});
    } else {
        !('plugin' in _global) && (_global.cleanList = cleanList);
    }
}());